//
//  TeacherCourseListCell.m
//  优学荟管理系统
//
//  Created by 星道 on 17/6/26.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "TeacherCourseListCell.h"

@implementation TeacherCourseListCell
{
    IBOutlet UILabel *_Course;
    IBOutlet UIButton *shelf_Btn;
}




/**
 点击了评价事件
 */
- (IBAction)ClickButton:(UIButton *)sender
{
    if (self.ClickButton)
    {
        self.ClickButton (self.Model.ID);
    }
}

/**
 点击了集体评价
 */
- (IBAction)ClickEva:(UIButton *)sender
{
    if (self.ClickEva)
    {
        self.ClickEva (self.Model.ID);
    }
}

/** 点击了课程编辑 */
- (IBAction)ClickUpload:(UIButton *)sender {

    if (self.ClickUploadCourse) {

        self.ClickUploadCourse (self.Model.ID);
    }
}

/** 点击了上架或下架 */
- (IBAction)ClickSellStatus:(UIButton *)sender {

    self.ClickSellStatus ? self.ClickSellStatus(self.Model,sender):nil;
}


- (void)setModel:(TeacherCourseListModel *)Model
{
    _Model = Model;

    _Course.text = Model.name;

    shelf_Btn.selected = [Model.sellStatus isEqualToNumber:@0] ? NO:YES;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    // 修改按钮的状态
    [shelf_Btn  setTitle:@"上架" forState:(UIControlStateNormal)];
    [shelf_Btn setTitle:@"下架" forState:(UIControlStateSelected)];
    [shelf_Btn setTitleColor:[UIColor grayColor] forState:(UIControlStateSelected)];
    [shelf_Btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [shelf_Btn setBackgroundImage:[self createImageWithColor:ColorRGB(240, 240, 240)] forState:(UIControlStateSelected)];
    [shelf_Btn setBackgroundImage:[UIImage imageNamed:@"btn_putaway_default"] forState:(UIControlStateNormal)];
}

//颜色转换图片
- (UIImage*)createImageWithColor:(UIColor*) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}
@end
